<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        input {
            width: 50px;
        }

        .box {
            width: 300px;
            height: 50px;
            margin: 100px auto;
        }
    </style>
</head>

<body>
    <div class="box">
        <input type="text" value="" id="inp">
        <button id="button">判断是不是两位数</button>
    </div>
</body>
<script>
    let button = document.getElementById("button");
    let inp = document.getElementById("inp");
    let num = 0
    inp.onkeyup = function () {
        num = inp.value
        console.log(num);
    }
    button.onclick = function () {
        // console.log(num.length);
        if (num.length == 2) {
            alert('ok!')
        } else {
            alert('这个数字是' + num.length + '数')
        }
    }
</script>

</html>